home *** CD-ROM | disk | FTP | other *** search
/ Computer Shopper 235 / Issue 235 - September 2007 - DPCS0907DVD.ISO / Extras / NetObjects Fusion / NOF10.exe / data1.cab / FSI / lib / nof / dialogs / FileDlg.js < prev    next >
Encoding:
Text File  |  2007-04-11  |  6.9 KB  |  196 lines

  1. /****i* SOURCE_FILE/INFO
  2.   *
  3.   * NAME
  4.   *  FileDlg.js
  5.   *
  6.   * USAGE
  7.   *  Part of Netobjects JavaScript Library.
  8.   *
  9.   * COPYRIGHT
  10.   *  Copyright ⌐ 2000-2005 Website Pros, Inc.
  11.   *  All Rights Reserved.
  12.   *
  13.   *  This is an unpublished work protected by Website Pros, Inc.
  14.   *  as a trade secret, and is not to be used or disclosed except as
  15.   *  expressly provided in a written license agreement executed by
  16.   *  you and Website Pros, Inc.
  17.   *
  18.   *      <copyright@websitepros.com>
  19.   *
  20.   * NOTES
  21.   *  JavaScript code.
  22.   *
  23.   *****/
  24.  
  25. if (!IS.isModuleInitialized("IS.NOF.DIALOGS.FileDlg"))
  26. {
  27.   
  28.   /****h* NOF_JavaScript_Library/NOF.DIALOGS.FileDlg
  29.     *
  30.     * NAME
  31.     *  NOF.DIALOGS.FileDlg
  32.     *
  33.     * DESCRIPTION
  34.     *    
  35.     * The <code>FileDlg</code> class displays a dialog to select a file or files.
  36.     * External dependencies: NOF.App
  37.     ****/
  38.   
  39.   /**
  40.     * constructor   
  41.     **/ 
  42.   function DIALOGS_FileDlg() {
  43.     this.__proto__ = DIALOGS_FileDlg.prototype;    
  44.     this.openDialog = null;
  45.   }
  46.   {
  47.     var member = DIALOGS_FileDlg.prototype;    
  48.     member.CLASS_NAME = "DIALOGS.FileDlg";
  49.     
  50.     var method = DIALOGS_FileDlg.prototype;                            
  51.       
  52.     /**
  53.     * Allows the user to select a directory in a dialog. 
  54.     * 
  55.     * @return the selected directory. If the user cancels the operation the function returns an empty string.
  56.     **/
  57.     method.selectDirectory = function () { 
  58.       return NOF.App.getFSIApp().SelectDirectory(); 
  59.     }
  60.     
  61.     /**
  62.     * Allows the user to select a file in a dialog. 
  63.     * 
  64.     * @param pLocation specifies the directory to open initially
  65.     * @return the path of the selected file. If the user cancels the operation the function returns an empty string.
  66.     **/        
  67.     method.selectFile = function (/*String*/ pLocation) { 
  68.       return NOF.App.getFSIApp().SelectFile(pLocation); 
  69.     }        
  70.  
  71.     /**
  72.     * Allows the user to select multiple files in a dialog. 
  73.     * @param pLocation specifies the directory to open initially    
  74.     * @param dialogTitle title of the file chooser dialog
  75.     * @param okButtonText
  76.     * @param cancelButtonText
  77.     * @param tipText
  78.     * @param tipValueText
  79.     * @param filters list of file filter objects. A file filter is an object with "text" and "value" members.
  80.     * The value member should contain the list of file names patterns. 
  81.     * Example of a filters object: 
  82.     * var filters = [ { text: "web images", value: "*.gif;*.jpg;*.jpeg" }, { text: "not web images", value: "*.bmp;*.psd" } ];
  83.     * @return the list (Array) containing the paths of selected files. If the user cancels the operation the function returns null.
  84.     **/        
  85.     method.selectFiles = function (/*String*/ pLocation,/*String*/ dialogTitle, /*String*/ okButtonText,/*String*/ cancelButtonText,/*String*/ tipText,/*String*/ tipValueText, /*FileFilter[]*/ filters) {             
  86.       this.openDialog = new ActiveXObject(NOF.ProgId.FSIFileOpenDlg);            
  87.       var toRet = this.selectMultipleFiles(pLocation, dialogTitle, okButtonText, cancelButtonText, tipText, tipValueText, filters);            
  88.       this.openDialog = null;
  89.       return toRet;
  90.     }
  91.     
  92.     /**
  93.     * Allows the user to select multiple images files in a dialog. 
  94.     * @param pLocation specifies the directory to open initially    
  95.     * @param dialogTitle title of the file chooser dialog
  96.     * @param okButtonText
  97.     * @param cancelButtonText
  98.     * @param tipText
  99.     * @param tipValueText
  100.     * @param filters list of file filter objects. A file filter is an object with "text" and "value" members.
  101.     * The value member should contain the list of file names patterns. 
  102.     * Example of a filters object: 
  103.     * var filters = [ { text: "web images", value: "*.gif;*.jpg;*.jpeg" }, { text: "not web images", value: "*.bmp;*.psd" }
  104.     * @param useFileNameText label for "Use File Name"
  105.     * @param useFileNameChecked checkbox selection state
  106.     * @return an object with 2 members: 
  107.     *     fileList - the list (Array) containing the paths of selected file. 
  108.     *     isChecked - true if the "Use File Name" checkbox was checked, false if not.
  109.     * If the user cancels the operation the function returns null.
  110.     **/        
  111.     method.selectImageFiles = function (/*String*/ pLocation,/*String*/ dialogTitle, /*String*/ okButtonText,/*String*/ cancelButtonText,/*String*/ tipText,/*String*/ tipValueText, /*FileFilter[]*/ filters,/*String*/ useFileNameText,/*boolean*/ useFileNameChecked) { 
  112.       this.openDialog = new ActiveXObject(NOF.ProgId.FSIImageOpenDlg);    
  113.       
  114.       var toRet = null;
  115.       
  116.       if (useFileNameText != null) {
  117.         this.openDialog.SetUseFileNameText(useFileNameText);
  118.       }
  119.       if (typeof(useFileNameChecked) == 'boolean') {
  120.         //alert("useFileNameChecked " + useFileNameChecked);
  121.         this.openDialog.SetUseFileNameChecked( (useFileNameChecked) ? 1 : 0 );
  122.       }
  123.       
  124.       var fileList = this.selectMultipleFiles(pLocation, dialogTitle, okButtonText, cancelButtonText, tipText, tipValueText, filters);
  125.       if (fileList != null) {
  126.       
  127.         toRet = new Object();
  128.         toRet.fileList = fileList;
  129.         toRet.isChecked    = (this.openDialog.IsCheckedUseFileName() > 0);
  130.       }
  131.       
  132.       this.openDialog = null;
  133.       return toRet;
  134.     }
  135.     
  136.     /**
  137.     * !this should not be a public method!
  138.     **/
  139.     method.selectMultipleFiles = function (/*String*/ pLocation,/*String*/ dialogTitle, /*String*/ okButtonText,/*String*/ cancelButtonText,/*String*/ tipText,/*String*/ tipValueText, /*FileFilter[]*/ filters) { 
  140.       //  
  141.       if (this.openDialog == null) {
  142.         return null;
  143.       }
  144.       
  145.       if (pLocation != null) {
  146.         this.openDialog.SetInitialDirectory(pLocation);
  147.       }
  148.       
  149.       if (dialogTitle != null) {
  150.         this.openDialog.SetDialogTitle(dialogTitle);
  151.       }
  152.       
  153.       if (okButtonText != null) {
  154.         this.openDialog.SetOkButtonText(okButtonText);
  155.       }
  156.       
  157.       if (cancelButtonText != null) {
  158.         this.openDialog.SetCancelButtonText(cancelButtonText);
  159.       }
  160.       
  161.       if (tipText != null) {
  162.         this.openDialog.SetTipText(tipText);
  163.       }
  164.       
  165.       if (tipValueText != null) {
  166.         this.openDialog.SetTipValueText(tipValueText);
  167.       }            
  168.       
  169.       if (filters != null) {
  170.         for (var i=0; i < filters.length; i++) {
  171.           this.openDialog.AddFilter(filters[i].text, filters[i].value);
  172.         }
  173.       }
  174.       
  175.       if (this.openDialog.Open() == 1) {
  176.       
  177.         var fileList    = this.openDialog.GetSelectedFiles();                                
  178.       
  179.         if (fileList == null) {                    
  180.           return null;
  181.         }
  182.       
  183.         var toRet = new Array();
  184.         
  185.         for (var i = fileList.lbound( 1 ); i <= fileList.ubound( 1 ); i++ ) {                    
  186.           toRet[toRet.length] = fileList.getItem( i );
  187.         }                
  188.       
  189.         return toRet;
  190.       }
  191.       
  192.       return null; 
  193.     }        
  194.   }
  195.   DIALOGS.__proto__.FileDlg = DIALOGS_FileDlg;
  196. }